export class Player {
  constructor(id, name, isAI = false, avatar = null) {
    this.id = id;
    this.name = name;
    this.isAI = isAI;
    this.avatar = avatar || this.getDefaultAvatar();
    this.cards = [];
    this.starCoins = 100; // 初始星光币
    this.seatIndex = -1; // 座位索引
  }

  getDefaultAvatar() {
    const avatars = ['👤', '🤖', '👨', '👩', '🧑', '👴', '👵'];
    return avatars[Math.floor(Math.random() * avatars.length)];
  }

  // 添加牌到手牌
  addCard(card) {
    this.cards.push(card);
  }

  // 移除手牌
  removeCards(cardsToRemove) {
    cardsToRemove.forEach(cardToRemove => {
      const index = this.cards.findIndex(c => c.id === cardToRemove.id);
      if (index !== -1) {
        this.cards.splice(index, 1);
      }
    });
  }

  // 检查是否有指定的牌
  hasCards(cards) {
    return cards.every(card => 
      this.cards.some(c => c.id === card.id)
    );
  }

  // 更新星光币
  updateStarCoins(amount) {
    this.starCoins += amount;
    if (this.starCoins < 0) {
      this.starCoins = 0;
    }
  }

  // 获取可以组成的对子
  getPossiblePairs() {
    const pairs = [];
    
    for (let i = 0; i < this.cards.length - 1; i++) {
      for (let j = i + 1; j < this.cards.length; j++) {
        if (this.cards[i].canPairWith(this.cards[j])) {
          pairs.push([this.cards[i], this.cards[j]]);
        }
      }
    }
    
    return pairs;
  }
}